<?php
App::uses('AppController', 'Controller');
/**
 * Tipospagos Controller
 *
 * @property Tipospago $Tipospago
 * @property PaginatorComponent $Paginator
 */
class TipospagosController extends AppController {

/**
 * Components
 *
 * @var array
 */
	public $components = array('Paginator');
        
        public $uses = array('Tipospago');
        
        public $layout = 'sib';

/**
 * index method
 *
 * @return void
 */
	
        public function index(){
            $tipospagos = $this->Tipospago->find('all', array(
                'recursive'=>-1,
                'order'=>array('Tipospago.id DESC')
            ));
            $this->set(compact('tipospagos'));
        }

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		if (!$this->Tipospago->exists($id)) {
			throw new NotFoundException(__('Invalid tipospago'));
		}
		$options = array('conditions' => array('Tipospago.' . $this->Tipospago->primaryKey => $id));
		$this->set('tipospago', $this->Tipospago->find('first', $options));
	}

/**
 * add method
 *
 * @return void
 */
        public function add()
    {
        if (!empty($this->request->data)) {
            $this->Tipospago->create();
            //debug($this->request->data);die;
            if ($this->Tipospago->save($this->request->data)) {
                $this->Session->setFlash('Tipo Pago registrado con exito', 'msgbueno');
                $this->redirect(array('action' => 'index'), null, true);
            } else {
                $this->Session->setFlash('No se pudo registrar el Tipo de pago','msgerror');
            }
        }
    }

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null)
    {
        $this->Tipospago->id = $id;
        if (!$id) {
            $this->Session->setFlash('No existe el Tipo de Pago');
            $this->redirect(array('action' => 'index'), null, true);
        }
        if (empty($this->request->data)) {
            $this->request->data = $this->Tipospago->read();
        } else {
            if ($this->Tipospago->save($this->request->data)) {
                $this->Session->setFlash('Los datos fueron modificados', 'msgbueno');
                $this->redirect(array('action' => 'index'), null, true);
            } else {
                $this->Session->setFlash('no se pudo modificar!!','msgerror');
            }
        }
    }

/**
 * delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		$this->Tipospago->id = $id;
		if (!$this->Tipospago->exists()) {
			throw new NotFoundException(__('Invalid tipospago'));
		}
		$this->request->onlyAllow('post', 'delete');
		if ($this->Tipospago->delete()) {
			$this->Session->setFlash(__('The tipospago has been deleted.'));
		} else {
			$this->Session->setFlash(__('The tipospago could not be deleted. Please, try again.'));
		}
		return $this->redirect(array('action' => 'index'));
	}}
